package com.example.sunmiv1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.VipRecordBean;
import com.example.sunmiv1.views.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TodayRecordAdapter extends BaseAdapter {

    private Context context;
    private List<VipRecordBean.DataBean> list;
    ViewHolder viewHolder;

    public TodayRecordAdapter(Context context, List<VipRecordBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.vip_details_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        String type = list.get(position).getType();
        if("1".equals(type)||"3".equals(type)){
            viewHolder.vipDetailsAdapterImg.setImageResource(R.mipmap.vip_details_recharge);
        }else if("6".equals(type)||"7".equals(type)||"8".equals(type)){
            viewHolder.vipDetailsAdapterImg.setImageResource(R.mipmap.vip_details_activity);
        }else if("5".equals(type)||"9".equals(type)){
            viewHolder.vipDetailsAdapterImg.setImageResource(R.mipmap.vip_details_refund);
        }else if("4".equals(type)){
            viewHolder.vipDetailsAdapterImg.setImageResource(R.mipmap.deduction);
        }else{
            viewHolder.vipDetailsAdapterImg.setImageResource(R.mipmap.vip_details_consume);
        }
        viewHolder.vipDetailsAdapterMoney.setText("$" + list.get(position).getAll_money());
        viewHolder.vipDetailsAdapterMsg.setText(list.get(position).getRemark());
        viewHolder.vipDetailsAdapterStore.setText(context.getResources().getString(R.string.vipRecord_shopOwner));
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.vipDetails_adapter_img)
        CircleImageView vipDetailsAdapterImg;
        @BindView(R.id.vipDetails_adapter_money)
        TextView vipDetailsAdapterMoney;
        @BindView(R.id.vipDetails_adapter_msg)
        TextView vipDetailsAdapterMsg;
        @BindView(R.id.vipDetails_adapter_store)
        TextView vipDetailsAdapterStore;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
